import java.util.Scanner;


public class escudosRomanos {

	public static void main(String[] args) {
		Scanner leer = new Scanner(System.in);
		int aux = leer.nextInt();
		while(aux!=0){
			int suma=0;
			int tmp=0;
			while(aux!=0){
				tmp = (int) Math.sqrt(aux);
				aux= aux-(tmp*tmp);
				suma += (tmp*tmp)+tmp*4; 
			}
			System.out.println(suma);
			aux = leer.nextInt();
		}
	}
}
